{% extends 'base.html' %}

{% block title %}编辑用户 - {{ user.username }} - Django RBAC 项目{% endblock %}

{% block content %}
    <div class="min-h-screen bg-gray-50 py-12 sm:px-6 lg:px-8">
        <div class="max-w-3xl mx-auto">
            <div class="bg-white shadow overflow-hidden sm:rounded-lg">
                <div class="px-4 py-5 sm:px-6">
                    <h3 class="text-lg leading-6 font-medium text-gray-900">
                        编辑用户: {{ form.username }}
                    </h3>
                    <p class="mt-1 max-w-2xl text-sm text-gray-500">
                        修改用户的基本信息
                    </p>
                </div>
                <div class="border-t border-gray-200">
                    <form method="post" class="divide-y divide-gray-200">
                        {% csrf_token %}
                        {% for field in form %}
                            <div class="px-4 py-5 sm:px-6">
                                <div class="grid grid-cols-3 gap-4">
                                    <label for="{{ field.id_for_label }}"
                                           class="block text-sm font-medium text-gray-500">
                                        {% if field.name == 'username' %}
                                            用户名
                                        {% elif field.name == 'email' %}
                                            电子邮箱
                                        {% elif field.name == 'is_active' %}
                                            账号状态
                                        {% else %}
                                            {{ field.label }}
                                        {% endif %}
                                    </label>
                                    <div class="col-span-2">
                                        {{ field }}
                                        {% if field.name == 'username' %}
                                            <p class="mt-2 text-sm text-gray-500">必填。150个字符或更少。只能包含字母、数字和
                                                @/./+/-/_ 字符。</p>
                                        {% elif field.help_text %}
                                            <p class="mt-2 text-sm text-gray-500">{{ field.help_text }}</p>
                                        {% endif %}
                                        {% for error in field.errors %}
                                            <p class="mt-2 text-sm text-red-600">{{ error }}</p>
                                        {% endfor %}
                                    </div>
                                </div>
                            </div>
                        {% endfor %}
                        <div class="px-4 py-5 sm:px-6">
                            <div class="flex justify-between">
                                <a href="{% url 'user_list' %}"
                                   class="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                                    返回用户列表
                                </a>
                                <div>
                                    <button type="submit"
                                            class="inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
                                        保存更改
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

